import { Controller, AppEvent } from "../../framework/framework";
import { } from '../models/model';
import { } from '../views/view';

class DefaultController extends Controller implements IController {
    private _newsModel: IModel;
    private _homeView: IView;

    constructor(metiator: IMediator) {
        super(metiator);
        this._newsModel = new IndexModel(metiator);
        this._homeView = new IndexView(metiator);
    }

    // initialize views/ models and strat listening to controller actions
    public initialize(): void {
        // subscribe to controller action events
        this.subscribeToEvents([
            new AppEvent("app.controller.index.index", null, (e, symbol: string) => { this.index(symbol); })
        ]);

        // initialize view and models events
        this._newsModel.initialize();
        this._homeView.initialize();
    }

    // dispose views/models and stop listening to controller actions
    public dispose(): void {

        // dispose the controller events
        this.unsubscribeToEvents();

        // dispose views and model events
        this._newsModel.dispose();
        this._homeView.dispose();
    }

    public index(args: any) {
        this.triggerEvent(new AppEvent("app.model.index.index", args, null));
    }
}

export { DefaultController };
